package com.ruoyi.statistics.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.statistics.domain.ProductStatistics;
import com.ruoyi.statistics.domain.Statistics;
import com.ruoyi.statistics.mapper.StatisticsMapper;
import com.ruoyi.statistics.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 销售统计Service业务层处理
 *
 * @author zjh
 * @date 2022-06-09
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private StatisticsMapper statisticsMapper;

    @Override
    public List<Statistics> selectClientStatisticsList(Statistics statistics)
    {
        statistics.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        return statisticsMapper.selectClientStatisticsList(statistics);
    }
//    @Override
//    public List<Statistics> selectClientStatisticsListCount(Statistics statistics)
//    {
//        statistics.setDeptId(ShiroUtils.getSysUser().getCompanyId());
//        return statisticsMapper.selectClientStatisticsListCount(statistics);
//    }
    @Override
    public Statistics selectClientStatisticsListCount(Statistics statistics)
    {
        statistics.setDeptId(ShiroUtils.getSysUser().getCompanyId());
        return statisticsMapper.selectClientStatisticsListCount(statistics);
    }

    @Override
    public List<ProductStatistics> selectProductStatisticsList(ProductStatistics productStatistics)
    {
        productStatistics.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        return statisticsMapper.selectProductStatisticsList(productStatistics);
    }
    @Override
    public ProductStatistics selectProductStatisticsListCount(ProductStatistics productStatistics)
    {
        productStatistics.setDeptId(ShiroUtils.getSysUser().getCompanyId());
        return statisticsMapper.selectProductStatisticsListCount(productStatistics);
    }

    @Override
    public Statistics selectStatisticsToIndex()
    {
        SysUser sysUser=SecurityUtils.getLoginUser().getUser();
        Statistics statistics=new Statistics();
        statistics.setDeptId(sysUser.getCompanyId());
        if (!sysUser.getDeptId().equals(sysUser.getCompanyId())){
            statistics.setUserId(sysUser.getUserId());
        }
        return statisticsMapper.selectStatisticsToIndex(statistics);
    }

    @Override
    public List<ProductStatistics> selectDeptObj(Long deptId) {
        return statisticsMapper.selectProductStatisticsNameList(deptId);
    }


    @Override
    public List<ProductStatistics> selectProductStatisticsTypeList(Long deptId) {
        return statisticsMapper.selectProductStatisticsTypeList(deptId);
    }




    @Override
    public List<ProductStatistics> selectProductStatisticsTypeByNameList(ProductStatistics productStatistics)
    {
        productStatistics.setDeptId(ShiroUtils.getSysUser().getCompanyId());
        return statisticsMapper.selectProductStatisticsTypeByNameList(productStatistics);
    }

}
